
const {ccclass, property} = cc._decorator;

@ccclass
export default class showTips extends cc.Component {

    label: cc.Label = null;
    text:string = null;
    index: number = 0;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.label = this.getComponent(cc.Label);
        this.text = this.label.string;
        
        
        this.node.color = cc.color(234, 146, 32, 255);
        this.repeat();
    }

    start () {

    }

    repeat() {
        this.label.string = '';  // 清空文本，从新显示
        this.schedule(this.onTimer,0.3)
        
    }

    onTimer() {
        this.index ++;
        let str:string = this.text.substring(0, this.index);
        this.label.string = str;
        if (this.index >= this.text.length) {
            this.unschedule(this.onTimer);
            this.index = 0;
        }
    }
    // update (dt) {}
}
